/*
 * 软件著作权：北京康兰尚德数据科技有限公司
 * 项目名称：康兰数据购物中心分析平台
 *
 * NAME : NewBrandDaoImpl.java
 *
 * PURPOSE : 新品数据库访问
 *
 * AUTHOR : EEDATA/ywb
 *
 *
 * 创建日期: 2013-11-27
 * HISTORY：
 * 变更日期 
 */
package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import pojo.EcpPpBrandcomment;
import pojo.EcpPpNewbrand;
import pojo.EcpPpPraise;
import util.HibernateUtils;

/**
 * 新品数据访问层
 * 
 * @author ywb
 */

public class NewBrandDaoImpl {

    /**
     * 根据品牌id查询新品相关信息
     */
    @SuppressWarnings("unchecked")
    public List<EcpPpNewbrand> selectNewBrand(String brandid) {// 二、getNewProductInfoList接口
        Session session = null;
        Transaction ts = null;
        List<EcpPpNewbrand> list = null;
        try {
            session = HibernateUtils.getSession();
            ts = session.beginTransaction();

            Query query = session.createQuery("from EcpPpNewbrand where brandid=?");
            query.setParameter(0, brandid);
            list = query.list();

            ts.commit();

        } catch (Exception e) {
            e.printStackTrace();
            ts.rollback();
        } finally {
            HibernateUtils.closeSession(session);
        }

        return list;

    }


    /**
     * 根据新品id查询评论个数
     */
    @SuppressWarnings("unchecked")
    public int selectCommBrandothersNum(String newbrandid) {// 二、getNewProductInfoList接口
        Session session = null;
        Transaction ts = null;
        int num = 0;
        try {
            session = HibernateUtils.getSession();
            ts = session.beginTransaction();

            Query query = session.createQuery("from EcpPpBrandcomment where braotherid=?");
            query.setParameter(0, Integer.parseInt(newbrandid));
            List<EcpPpBrandcomment> list = query.list();
            num = list.size();

            ts.commit();

        } catch (Exception e) {
            e.printStackTrace();
            ts.rollback();
        } finally {
            HibernateUtils.closeSession(session);
        }

        return num;

    }


    /**
     * 根据新品id查询赞个数
     */
    @SuppressWarnings("unchecked")
    public int selectPriseNum(String newbrandid) {// 二、getNewProductInfoList接口
        Session session = null;
        Transaction ts = null;
        int num = 0;
        try {
            session = HibernateUtils.getSession();
            ts = session.beginTransaction();

            Query query = session.createQuery("from EcpPpPraise where braotherid=?");
            query.setParameter(0, Integer.parseInt(newbrandid));
            List<EcpPpPraise> list = query.list();
            num = list.size();

            ts.commit();

        } catch (Exception e) {
            e.printStackTrace();
            ts.rollback();
        } finally {
            HibernateUtils.closeSession(session);
        }

        return num;

    }
}
